'use strict'

// 定义数字0:
var sum=0;

var zero = function (f) {
    return function (x) {
        return x;
    }
};



var one = function (f) {  
    sum=sum+1;
    console.log(1);
    console.log(f);
    return function (x) {
        sum=sum+1;
        console.log(2);
        console.log(x);
        return f(x);
    }
};


//let a=one(console.log)(1);
//f=console.log
//x=1
//f(x)=console.log(1)





function add(n, m) {
    sum=sum+1;
    console.log(3);
    console.log(n,m);
    return function (f) {
        sum=sum+1;
        console.log(4);
        console.log(f);
        return function (x) {
            sum=sum+1;
            console.log(5);
            console.log(x);
            return m(f)(n(f)(x));  //m()(n()())
        }
    }
}
var two = add(one, one);

let b=two(console.log)();
//n=one
//m=one
//f=console.log
//x=undefined
//m(f)=one(console.log)=f(x)
//n(f)(x)=one(console.log)(undefined)=undefined
//n(f)(x)=one(console.log)(undefined)=打印undefined/undefined
//m(f)(n(f)(x))=f(x),undefined
//

//one=console.log
console.log(sum);













// var three = add(one, two);

// var four = add(two,two);

// (two(function () {
//     console.log('print 2 times');
// }))();

// (three(function () {
//     console.log('print 3 times');
// }))();

// (four(function(){
//     console.log('print 4 times');
// }))();

// add(two,two)(function(){
//     console.log('print 4 times');
// })();

// add(two,two)(function(){})();

// let x1= add(two,two);
// let x2=x1(function(){});
// let x3=x2();



